#include "MTD.h"
#include "alfaBetaWithMemory.h"

#include <iostream>
#include <stdio.h>
#include <stdlib.h>



MTD::MTD(){}
//MTD::~MTD(){}


int MTD:: MTDF( Nodo *nodo, int f, int d, bool juegaNegro ){

    
    alfaBetaWithMemory alfabeta;
    
    int g = f;
    int beta;
    int upperbound = INT_MAX;
    int lowerbound = INT_MIN;
    do {
        if( g == lowerbound) {beta = g+1;}
        else {beta = g;}
        
        g = alfabeta.AlphaBetaWithMemory(nodo, beta-1, beta, d, juegaNegro);
        
        if( g < beta) {upperbound = g;}
        else { lowerbound = g; }
    } while(lowerbound < upperbound);
    
    nodGen = alfabeta.NodGen();
    
    return g;
}

int MTD::NodGen()const{
    return nodGen;
}
int MTD::Buscar( Nodo *nodo, int f, int d, bool juegaNegro ) {
    nodGen = 0;
    return MTDF(nodo, f, d, juegaNegro);
}


